 /*
  * Team Java
  * This is the cpu class that starts and runs the program.
  * Author(s): Michael Satran Jr, Michael Pogson, Stephen Hunter
  * Date: 5/31/2012
  */

#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "pcb.h"
#include "scheduler.h"
#include "io.h"
#include "display.h"

void* cpu_loop(void *arg)
{
	int i = 0;
	while(i < 1000000000000)
	{
		i++;
	}
}

int main(void)
{

	char * input = (char *) malloc(sizeof(char) * 5);

	printf("How many processes would you like? ");
	gets(input);
	int num_processes = atoi(input);
	
	printf("How long would you like to run? ");
	gets(input);
	int length = atoi(input);

	initScheduler();

	Process proc[num_processes];

	int i;
	for (i = 0; i < num_processes; i++)
	{

		proc[i].steps_n = 1000;
		proc[i].requests_n = 10;
		int j = 0;
		for (; j < 10; j++)
		{
			proc[i].requests[j] = io_system_call;
		}

		addProcess(&proc[i]);

	}
	
	pthread_t threads[2];
	pthread_attr_t attr;

	pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
	
	
	pthread_create(&threads[0], &attr, start, NULL);
	i = 0;
	while(i < 1){
	
		pthread_create(&threads[i + 1], &attr,runNextProcess , NULL);
	
	}
	
	for(i = 0; i < 2; i++) {
	pthread_join(threads[i], NULL);
	}
	pthread_exit(NULL);
	
	return 0;
}